﻿using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;

var Claim = new List<Claim>();
Claim.Add(new Claim(ClaimTypes.Name, "yhs"));
Claim.Add(new Claim(ClaimTypes.HomePhone, "1578139612"));
Claim.Add(new Claim(ClaimTypes.Role, "admin"));
string key = "fasdfad&9045dfddfsdfsdfdsfafz222#fadpio@0232";//未篡改的key
//string key = "fasdfad&9045dfddfsdfsdfdsfafz222rrrr#fadpio@0232";//串改的key
DateTime expires = DateTime.Now.AddDays(1);
byte[] secBytes = Encoding.UTF8.GetBytes(key);
var secKey = new SymmetricSecurityKey(secBytes);
var credentials = new SigningCredentials(secKey, SecurityAlgorithms.HmacSha256Signature);
var tokenDescriptor = new JwtSecurityToken(claims: Claim,
    expires: expires, signingCredentials: credentials);
string jwt = new JwtSecurityTokenHandler().WriteToken(tokenDescriptor);
Console.WriteLine(jwt);
Console.ReadLine();

